home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / p063b9s.zip / UNIT / EXTEND.PAS < prev    next >
Pascal/Delphi Source File  |  1996-04-20  |  6KB  |  155 lines

  1. {$I-,O-,R-}
  2.  
  3. unit Extend;
  4.  
  5. { This unit allows a program to open more than the standard DOS maximum of 20
  6.   open files at one time.  You must also be sure to set a FILES=XX statement
  7.   in your CONFIG.SYS file.  This program installs a special interrupt handler
  8.   under DOS 2.x, some semi-documented features under DOS 3.x prior to
  9.   DOS 3.3 and the DOS extend files call under DOS 3.3 or later.  This
  10.   unit USES the DOS unit and should be used before any other units other than
  11.   the DOS unit.  This code was based upon earlier work by Randy Forgaard, Bela
  12.   Lubkin and Kim Kokkonen.  See EXTEND.DOC for more information.
  13.  
  14.   Scott Bussinger
  15.   Professional Practice Systems
  16.   110 South 131st Street
  17.   Tacoma, WA  98444
  18.   (206)531-8944
  19.   Compuserve [72247,2671] }
  20.  
  21. { ** Revision History **
  22.   1 EXTEND.PAS 9-Mar-89,`SCOTT' First version using TLIB -- Based on 3.2
  23.   2 EXTEND.PAS 15-Sep-89,`SCOTT'
  24.            Added SwapVectorsExtend procedure
  25.            Put handle table into DOS memory
  26.            Use DOS 3.3 extended handles function when available
  27.   3 EXTEND.PAS 2-Oct-89,`SCOTT'
  28.            Fixed bug in determining the DOS version
  29.   4 EXTEND.PAS 5-Oct-89,`SCOTT'
  30.            Yet another bug in the DosVersion detection
  31.   5 EXTEND.PAS 19-Nov-90,`SCOTT'
  32.            New version of EXTEND that is compatible with Turbo Pascal 6.0
  33.            Modified the documentation and version numbers to be less confusing
  34.   ** Revision History ** }
  35.  
  36. interface
  37.  
  38. {$IFNDEF DPMI}
  39. procedure SwapVectorsExtend;
  40.   { Swap interrupt vectors taken over by Extend unit with system vectors }
  41. {$ENDIF}
  42.  
  43. implementation
  44.  
  45. uses Use32, Dos{$IFNDEF DPMI}, Shrink{$ENDIF};
  46.  
  47. type HandleArray = array[0..254] of byte;        { Room for 255 handles }
  48.      HandleArrayPtr = ^HandleArray;
  49.  
  50. var DosMemory: pointer;                          { Pointer to memory gained from DOS }
  51.     ExitSave: pointer;                           { Previous exit procedure }
  52.     OldInt21: pointer;                           { Save old INT 21 }
  53.     OldHandleTable: HandleArrayPtr;              { Pointer to original table }
  54.     OldNumHandles: byte;                         { Original number of handles }
  55.  
  56. {$IFNDEF DPMI}
  57.  
  58. {$L EXTEND }
  59. procedure ExtendInit; external;                  { Initialize interrupt handler }
  60. procedure ExtendHandler; external;               { Replacement INT 21 handler }
  61.  
  62. procedure SwapVectorsExtend;
  63.   { Swap interrupt vectors taken over by Extend unit with system vectors }
  64. var
  65.   TempVector: pointer;
  66. begin
  67.   if lo(DosVersion) = 2 then
  68.   begin
  69.     GetIntVec($21,TempVector);                   { Swap the INT 21 vectors }
  70.     SetIntVec($21,OldInt21);
  71.     OldInt21 := TempVector
  72.   end
  73. end;
  74.  
  75. procedure ExtendHandles;
  76.   { Install the extended handles interrupt.  No files (other than
  77.     standard handles) should be open when unit starts up. }
  78. var
  79.   Regs: Registers;
  80. begin
  81.   if lo(DosVersion) <= 2 then
  82.   begin
  83.     GetIntVec($21,OldInt21);                     { Install interrupt handler under DOS 2.x }
  84.     ExtendInit;                                  { Initialize the interrupt handler }
  85.     SetIntVec($21,@ExtendHandler)
  86.   end else
  87.   begin
  88.     DosNewShrink(DosMemory,sizeof(HandleArray));
  89.     if DosMemory <> nil then                     { There wasn't enough memory for a handle table, so just quit }
  90.       if (lo(DosVersion)>=4) or (hi(DosVersion)>=30) then { Does this DOS version support the handles call? }
  91.       begin
  92.         DosDispose(DosMemory);                   { Free up the DOS memory block so that the next function will succeed }
  93.         with Regs do
  94.         begin
  95.           AH := $67;                             { Tell DOS to allow us 255 handles }
  96.           BX := 255;                             { KEEP THIS NUMBER ODD TO AVOID BUG IN SOME VERSIONS OF DOS 3.3!! }
  97.           MsDos(Regs)
  98.         end
  99.       end else
  100.       begin
  101.         fillchar(DosMemory^,sizeof(HandleArray),$FF);     { Initialize new handles as unused }
  102.         OldNumHandles := mem[prefixseg:$0032];            { Get old table length }
  103.         OldHandleTable := pointer(ptr(prefixseg,$0034)^); { Save address of old table }
  104.         mem[prefixseg:$0032] := sizeof(HandleArray);      { Set new table length }
  105.         pointer(meml[prefixseg:$0034]) := DosMemory;      { Point to new handle table }
  106.         move(OldHandleTable^,DosMemory^,OldNumHandles)    { Copy the current handle table to the new handle table }
  107.       end
  108.   end
  109. end;
  110.  
  111. procedure ExitHandler; far;
  112.   { Uninstall the extended handles interrupt.  All files (other
  113.     than standard handles) should be closed before unit exits. }
  114. begin
  115.   ExitProc := ExitSave;                          { Chain to next exit routine }
  116.   SwapVectorsExtend                              { Restore original interrupt vectors }
  117. end;
  118.  
  119. {$ELSE}
  120.  
  121. procedure ExtendHandles;
  122.   { Install the extended handles interrupt.  No files (other than
  123.     standard handles) should be open when unit starts up. }
  124. var
  125.   Regs: Registers;
  126. begin
  127.   if lo(DosVersion) <= 2 then
  128.   begin
  129.  
  130.   end else
  131.   begin
  132.     if (lo(DosVersion)>=4) or (hi(DosVersion)>=30) then { Does this DOS version support the handles call? }
  133.     begin
  134.       with Regs do
  135.       begin
  136.         AH := $67;                             { Tell DOS to allow us 255 handles }
  137.         BX := 255;                             { KEEP THIS NUMBER ODD TO AVOID BUG IN SOME VERSIONS OF DOS 3.3!! }
  138.         MsDos(Regs)
  139.       end
  140.     end else
  141.     begin
  142.     end
  143.   end
  144. end;
  145.  
  146. {$ENDIF}
  147.  
  148. begin
  149. {$IFNDEF DPMI}
  150.   ExitSave := ExitProc;                          { Remember the previous exit routine }
  151.   ExitProc := @ExitHandler;                      { Install our exit routine }
  152. {$ENDIF}
  153.   ExtendHandles                                  { Enable the extra handles }
  154. end.
  155.